package com.csoa.community.activity;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;

import com.csoa.community.R;
import com.csoa.community.adapter.GalleryAdapter;
import com.csoa.community.adapter.OffDocAdapter;
import com.csoa.community.adapter.ViewPagerAdapter;
import com.csoa.community.bean.OfficialDocBean;
import com.csoa.community.bean.UserBean;
import com.csoa.community.net.WcfAsyncTask;
import com.csoa.community.requests.AbstractRequest;
import com.csoa.community.requests.OffDocApprovalRequest;
import com.csoa.community.requests.OffDocDetailMeetingRequest;
import com.csoa.community.requests.OffDocHaveReadRequest;
import com.csoa.community.requests.OffDocSearchRequest;
import com.csoa.community.requests.OffDocToBeReadRequest;
import com.csoa.community.singletons.GlobalVars;
import com.csoa.community.utils.AndroidUtils;
import com.csoa.community.utils.StringUtils;
import com.csoa.community.widget.NarView;
import com.csoa.community.widget.PullToRefreshBase.OnRefreshListener;
import com.csoa.community.widget.PullToRefreshListView;

public class OfficialDocActivity extends BaseActivity {

	private ArrayList<View> mViewList;
	private ViewPagerAdapter mAdapter;
	private ViewPager mViewPager;
	private Gallery mGallery;
	private GalleryAdapter mOfficialAdapter;
	private PullToRefreshListView mToBeReadPullListView;
	private ListView mToBeReadListView;

	private PullToRefreshListView mHaveReadPullListView;
	private ListView mHaveReadListView;

	public static List<OfficialDocBean> mToBeReadOfficialDocs = new ArrayList<OfficialDocBean>();
	public static List<OfficialDocBean> mHaveReadOfficialDocs = new ArrayList<OfficialDocBean>();
	private OffDocAdapter mToBeReadAdapter;
	private OffDocAdapter mHaveReadAdapter;
	private View mViewToBeRead;
	private View mViewHaveRead;
	private boolean[] mIsLoad = new boolean[] { false, false };
	protected int currentToBeReadPage = 1;
	protected int currentHaveReadPage = 1;
	
	protected int currentSearchToBeReadPage = 1;
	protected int currentSearchHaveReadPage = 1;
	
	
	ProgressBar mProgressToBeRead;
	ProgressBar mProgressHaveRead;
	protected boolean isPullRefreshHaveRead = false;
	protected boolean isPullRefreshToBeRead = false;
	private NarView narView;
	private boolean isMeeting = false;
	private ImageView mImgSearch;
	private boolean isFromSearch;
	private String title;
	private String owner;
	private String from;
	private String beginTime;
	private String endTime;

	@Override
	public void initData() {
		mToBeReadOfficialDocs.clear();

		mHaveReadOfficialDocs.clear();
		mToBeReadAdapter = new OffDocAdapter(OfficialDocActivity.this,
				mToBeReadOfficialDocs);
		mToBeReadListView.setAdapter(mToBeReadAdapter);

		if (GlobalVars.currentUser == null
				|| StringUtils.isEmpty(GlobalVars.currentUser.loginName)) {
			String strUsername = AndroidUtils.getGlobal(GlobalVars.LOGIN,
					GlobalVars.LOGIN_USERNAME, this);
			UserBean user = new UserBean();
			user.loginName = strUsername;
			GlobalVars.currentUser = user;

		}

		buildRequestToBeRead(GlobalVars.currentUser.loginName,
				currentToBeReadPage, true);

		mToBeReadPullListView.setOnRefreshListener(new OnRefreshListener() {

			@Override
			public void onRefresh() {
				if (mToBeReadPullListView.hasPullFromTop()) {
					isPullRefreshToBeRead = true;
					currentToBeReadPage = 1;
					buildRequestToBeRead(GlobalVars.currentUser.loginName,
							currentToBeReadPage, true);
				} else {
					isPullRefreshToBeRead = false;
					if (!isFromSearch) {
						buildRequestToBeRead(GlobalVars.currentUser.loginName,
								currentToBeReadPage, false);
					} else {
						buildSearchRequestToBeRead(
								GlobalVars.currentUser.loginName,
								currentSearchToBeReadPage, title, owner, from,
								beginTime, endTime, false);
					}
				}

			}
		});
		mToBeReadListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				OfficialDocBean offDocDetail = mToBeReadOfficialDocs
						.get(position);
				buildRequestMeeting(offDocDetail.ID, offDocDetail.RID,
						GlobalVars.ISSUED, false,
						GlobalVars.READ_TYPE_TO_BE_READ, GlobalVars.TO_BE_READ,
						position);
			}
		});

		mHaveReadAdapter = new OffDocAdapter(OfficialDocActivity.this,
				mHaveReadOfficialDocs);
		mHaveReadListView.setAdapter(mHaveReadAdapter);
		mHaveReadPullListView.setOnRefreshListener(new OnRefreshListener() {

			@Override
			public void onRefresh() {
				if (mHaveReadPullListView.hasPullFromTop()) {
					isPullRefreshHaveRead = true;
					currentHaveReadPage = 1;
					buildRequestHaveRead(GlobalVars.currentUser.loginName,
							currentHaveReadPage, true);

				} else {
					isPullRefreshHaveRead = false;

					if (!isFromSearch) {
						buildRequestHaveRead(GlobalVars.currentUser.loginName,
								currentHaveReadPage, false);
					} else {
						buildSearchRequestHaveRead(
								GlobalVars.currentUser.loginName,
								currentSearchHaveReadPage, title, owner, from,
								beginTime, endTime, false);
					}

				}
			}
		});

		mHaveReadListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				OfficialDocBean offDocDetail = mHaveReadOfficialDocs
						.get(position);

				buildRequestMeeting(offDocDetail.ID, offDocDetail.RID,
						GlobalVars.ISUPDATE, false,
						GlobalVars.READ_TYPE_HAVE_READ, GlobalVars.HAVE_READ,
						position);
				// Intent intent = new Intent(OfficialDocActivity.this,
				// OffDocDetailActivity.class);
				// intent.putExtra("ID", offDocDetail.ID);
				// intent.putExtra("RID", offDocDetail.RID);
				// intent.putExtra(GlobalVars.READ_TYPE,
				// GlobalVars.READ_TYPE_HAVE_READ);
				// intent.putExtra("isupdate", false);
				// startActivity(intent);
			}
		});

	}

	private void initCenterUI(boolean isShowList, ListView list,
			ProgressBar progress) {
		list.setVisibility(View.VISIBLE);
		if (isShowList) {
			// if (list.getVisibility() != View.VISIBLE) {
			// list.setVisibility(View.VISIBLE);
			// }
			if (progress.getVisibility() != View.INVISIBLE) {
				progress.setVisibility(View.INVISIBLE);
			}
		} else {
			if (progress.getVisibility() != View.INVISIBLE) {
				progress.setVisibility(View.INVISIBLE);
			}
			if (progress.getVisibility() != View.VISIBLE) {
				progress.setVisibility(View.VISIBLE);
			}
		}
	}

	/**
	 * 
	 * @param ID
	 * @param RID
	 * @param readType
	 *            已读公文列表 未读公文列表
	 * @param issuedOrIsupdate
	 *            已读公文列表修改 未读公文列表的签收
	 * @param isMeeting
	 *            是否是会议
	 */
	protected void startActivity(String ID, String RID, String readType,
			String issuedOrIsupdateType, boolean issuedOrIsupdate,
			boolean isMeeting, int requestCode, int position, String strApproval) {
		Intent intent = new Intent(OfficialDocActivity.this,
				OffDocDetailActivity.class);

		intent.putExtra("ID", ID);
		intent.putExtra("RID", RID);
		intent.putExtra(GlobalVars.READ_TYPE, readType);
		intent.putExtra(issuedOrIsupdateType, issuedOrIsupdate);
		intent.putExtra("isMeeting", isMeeting);
		intent.putExtra("position", position);
		intent.putExtra("Approval", strApproval);
		startActivityForResult(intent, requestCode);

	}

	/**
	 * 获取待阅公文列表（ 构建待阅公文列表Request）
	 * 
	 * @param aUsername
	 * @param currPage
	 * @param isReload
	 */
	protected void buildRequestToBeRead(String aUsername, int currPage,
			boolean isReload) {
		if (isReload) {
			mToBeReadPullListView.showHeadView();
			initCenterUI(false, mToBeReadListView, mProgressToBeRead);
			isFromSearch = false;
		}
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("LogName", aUsername));
		params.add(new BasicNameValuePair("PageSize", GlobalVars.pageCount + ""));
		params.add(new BasicNameValuePair("CurrPage", currPage + ""));
		netRequestToBeRead(new OffDocToBeReadRequest(params), isReload);
	}

	/**
	 * 获取待阅公文列表
	 * 
	 * @param request
	 * @param isReload
	 *            true是刷新 false是加载更多
	 */
	private void netRequestToBeRead(AbstractRequest request,
			final boolean isReload) {
		new WcfAsyncTask(this, new OnUICallback() {

			@Override
			public void onGetResult(AbstractRequest request) {
				// dismisProgress();
				initCenterUI(true, mToBeReadListView, mProgressToBeRead);
				mToBeReadPullListView.onRefreshComplete();
				OffDocToBeReadRequest toBeReadRequest = (OffDocToBeReadRequest) request;
				if (toBeReadRequest.officialDocs != null) {
					if (isReload) {
						mIsLoad[0] = true;
						if (toBeReadRequest.officialDocs.size() == 0) {
							mToBeReadOfficialDocs.clear();
							mToBeReadAdapter.notifyDataSetChanged();
							OfficialDocActivity.this.showToast("暂无待阅公文");
							return;
						}
						currentToBeReadPage++;
						mToBeReadOfficialDocs.clear();
					} else {
						if (toBeReadRequest.officialDocs.size() == 0) {
							OfficialDocActivity.this.showToast("没有更多待阅公文");
							return;
						}
						currentToBeReadPage++;
					}
					mToBeReadOfficialDocs.addAll(toBeReadRequest.officialDocs);
					mToBeReadAdapter.notifyDataSetChanged();

				}
			}

			@Override
			public void onCancel() {
				if (isReload) {
					mIsLoad[0] = false;
				}
				// dismisProgress();
				initCenterUI(true, mToBeReadListView, mProgressToBeRead);
				mToBeReadPullListView.onRefreshComplete();
			}

			@Override
			public void onProgress(int progress, String msg) {
				// dismisProgress();
				OfficialDocActivity.this.showToast(msg);
			}
		}).execute(request);
	}

	/**
	 * 通过搜索获取待阅公文列表（ 构建搜索待阅公文列表Request）
	 * 
	 * @param aUsername
	 * @param currPage
	 * @param isReload
	 */
	protected void buildSearchRequestToBeRead(String aUsername, int currPage,
			String title, String owner, String from, String beginTime,
			String endTime, boolean isReload) {
		if (isReload) {
			mToBeReadPullListView.showHeadView();
			initCenterUI(false, mToBeReadListView, mProgressToBeRead);
		}
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("LogName", aUsername));
		params.add(new BasicNameValuePair("PageSize", GlobalVars.pageCount + ""));
		params.add(new BasicNameValuePair("CurrPage", currPage + ""));
//		params.add(new BasicNameValuePair("DataCount", GlobalVars.DataCount
//				+ ""));
		params.add(new BasicNameValuePair("Ttile", title));
		params.add(new BasicNameValuePair("Owner", owner));
		params.add(new BasicNameValuePair("FromDept", from));
		params.add(new BasicNameValuePair("DateType", ""));
		params.add(new BasicNameValuePair("BeginDate", beginTime));
		params.add(new BasicNameValuePair("EndDate", endTime));
		netSearchRequestToBeRead(new OffDocSearchRequest(
				GlobalVars.READ_TYPE_TO_BE_READ, params), isReload);
	}

	/**
	 * 通过搜索获取待阅公文列表
	 * 
	 * @param request
	 * @param isReload
	 *            true是刷新 false是加载更多
	 */
	private void netSearchRequestToBeRead(AbstractRequest request,
			final boolean isReload) {
		new WcfAsyncTask(this, new OnUICallback() {

			@Override
			public void onGetResult(AbstractRequest request) {
				// dismisProgress();
				initCenterUI(true, mToBeReadListView, mProgressToBeRead);
				mToBeReadPullListView.onRefreshComplete();
				OffDocSearchRequest toBeReadRequest = (OffDocSearchRequest) request;
				if (toBeReadRequest.officialDocs != null) {
					if (isReload) {
						isFromSearch = true;
						mIsLoad[0] = true;
						if (toBeReadRequest.officialDocs.size() == 0) {
							mToBeReadOfficialDocs.clear();
							mToBeReadAdapter.notifyDataSetChanged();
							OfficialDocActivity.this.showToast("您搜索的待阅公文暂不存在");
							isFromSearch = false;
							return;
						}
						currentSearchToBeReadPage++;
						mToBeReadOfficialDocs.clear();
					} else {
						if (toBeReadRequest.officialDocs.size() == 0) {
							OfficialDocActivity.this.showToast("您搜索的待阅公文没有更多了");
							return;
						}
						currentSearchToBeReadPage++;
					}
					mToBeReadOfficialDocs.addAll(toBeReadRequest.officialDocs);
					mToBeReadAdapter.notifyDataSetChanged();

				}
			}

			@Override
			public void onCancel() {
				initCenterUI(true, mToBeReadListView, mProgressToBeRead);
				mToBeReadPullListView.onRefreshComplete();
				isFromSearch = false;
			}

			@Override
			public void onProgress(int progress, String msg) {
				OfficialDocActivity.this.showToast(msg);
			}
		}).execute(request);
	}

	/**
	 * 通过搜索获取已阅公文列表（构建Request）
	 * 
	 * @param request
	 * @param isReload
	 *            true是刷新 false是加载更多
	 */
	protected void buildSearchRequestHaveRead(String aUsername, int currPage,
			String title, String owner, String from, String beginTime,
			String endtime, boolean isReload) {
		if (isReload) {
			mHaveReadPullListView.showHeadView();
			initCenterUI(false, mHaveReadListView, mProgressHaveRead);
		}
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("LogName", aUsername));
		params.add(new BasicNameValuePair("PageSize", GlobalVars.pageCount + ""));
		params.add(new BasicNameValuePair("CurrPage", currPage + ""));
		params.add(new BasicNameValuePair("DataCount", GlobalVars.DataCount
				+ ""));
		params.add(new BasicNameValuePair("Ttile", title));
		params.add(new BasicNameValuePair("Owner", owner));
		params.add(new BasicNameValuePair("FromDept", from));
		params.add(new BasicNameValuePair("DateType", ""));
		params.add(new BasicNameValuePair("BeginDate", beginTime));
		params.add(new BasicNameValuePair("EndDate", endtime));
		netSearchRequestHaveRead(new OffDocSearchRequest(
				GlobalVars.READ_TYPE_HAVE_READ, params), isReload);
	}

	/**
	 * 通过搜索获取已阅公文列表
	 * 
	 * @param request
	 * @param isReload
	 *            true是刷新 false是加载更多
	 */
	private void netSearchRequestHaveRead(AbstractRequest request,
			final boolean isReload) {
		new WcfAsyncTask(this, new OnUICallback() {

			@Override
			public void onGetResult(AbstractRequest request) {
				initCenterUI(true, mHaveReadListView, mProgressHaveRead);
				mHaveReadPullListView.onRefreshComplete();
				OffDocSearchRequest haveReadRequest = (OffDocSearchRequest) request;
				if (haveReadRequest.officialDocs != null) {
					if (isReload) {
						isFromSearch = true;
						mIsLoad[1] = true;
						if (haveReadRequest.officialDocs.size() == 0) {
							mHaveReadOfficialDocs.clear();
							mHaveReadAdapter.notifyDataSetChanged();
							OfficialDocActivity.this.showToast("您搜索的已阅公文暂不存在");
							isFromSearch = false;
							return;
						}
						currentSearchHaveReadPage++;
						mHaveReadOfficialDocs.clear();
					} else {
						if (haveReadRequest.officialDocs.size() == 0) {
							OfficialDocActivity.this.showToast("您搜索的已阅公文没有了");
							return;
						}
						currentSearchHaveReadPage++;
					}
					mHaveReadOfficialDocs.addAll(haveReadRequest.officialDocs);
					mHaveReadAdapter.notifyDataSetChanged();

				}
			}

			@Override
			public void onCancel() {
				isFromSearch = false;
				initCenterUI(true, mHaveReadListView, mProgressHaveRead);
				mHaveReadPullListView.onRefreshComplete();
			}

			@Override
			public void onProgress(int progress, String msg) {
				OfficialDocActivity.this.showToast(msg);
			}
		}).execute(request);
	}

	@Override
	public void initUI() {

		setContentView(R.layout.ui_official_doc);
		initNarView();

		mViewList = new ArrayList<View>();
		mViewToBeRead = getLayoutInflater().inflate(
				R.layout.ui_offical_doc_tobe_read, null);
		mViewList.add(mViewToBeRead);
		mViewHaveRead = getLayoutInflater().inflate(
				R.layout.ui_offical_doc_have_read, null);
		mViewList.add(mViewHaveRead);

		mViewPager = (ViewPager) findViewById(R.id.officialViewpager);

		mAdapter = new ViewPagerAdapter(getApplicationContext(), mViewList);
		mViewPager.setAdapter(mAdapter);

		mViewPager.setCurrentItem(0);

		mViewPager
				.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

					public void onPageSelected(int arg0) {
						mGallery.setSelection(arg0);
						handlerHaveRead(arg0);
					}

					public void onPageScrolled(int arg0, float arg1, int arg2) {

					}

					public void onPageScrollStateChanged(int arg0) {

					}
				});

		mGallery = (Gallery) findViewById(R.id.officialGallery);

		String[] gallery_titles = { "代办公文", "已办公文" };

		List<String> lstGalleryTitle = new ArrayList<String>();
		for (int i = 0; i < gallery_titles.length; i++) {
			lstGalleryTitle.add(gallery_titles[i]);
		}

		mOfficialAdapter = new GalleryAdapter(this, lstGalleryTitle);
		mGallery.setAdapter(mOfficialAdapter);

		mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				mOfficialAdapter.notifyDataSetChanged(position);
				mViewPager.setCurrentItem(position);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		mToBeReadPullListView = (PullToRefreshListView) mViewToBeRead
				.findViewById(R.id.officalListToBeRead);
		mHaveReadPullListView = (PullToRefreshListView) mViewHaveRead
				.findViewById(R.id.officalListHaveRead);
		mToBeReadListView = mToBeReadPullListView.getRefreshableView();
		mHaveReadListView = mHaveReadPullListView.getRefreshableView();
		mToBeReadListView.setVisibility(View.GONE);
		mProgressToBeRead = (ProgressBar) mViewToBeRead
				.findViewById(R.id.offToBeReadProgress);
		mProgressHaveRead = (ProgressBar) mViewHaveRead
				.findViewById(R.id.offHaveReadProgress);
		mImgSearch = (ImageView) this.findViewById(R.id.offSearchImg);
		mImgSearch.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				boolean isHaveRead = mGallery.getSelectedItemPosition() == 1 ? true
						: false;
				startSearchActivity(isHaveRead,
						isHaveRead == true ? GlobalVars.HAVE_READ
								: GlobalVars.TO_BE_READ);
			}
		});
	}

	public void startSearchActivity(boolean aIsHaveRead, int requestCode) {
		Intent intent = new Intent(OfficialDocActivity.this,
				OffDocSearchActivity.class);
		intent.putExtra("isHaveRead", aIsHaveRead);
		startActivityForResult(intent, requestCode);
	}

	private void initNarView() {
		narView = (NarView) this.findViewById(R.id.comNarView);
		narView.enterModule(narView.ids[0]);

		View topView = this.findViewById(R.id.off_doc_layout);
		topView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				narView.hiddenNav();
				return false;
			}
		});
	}

	protected void handlerHaveRead(int positon) {
		if (mIsLoad[positon]) {
			return;
		}
		if (positon == 0) {
			buildRequestToBeRead(GlobalVars.currentUser.loginName,
					currentToBeReadPage, false);
		} else {
			buildRequestHaveRead(GlobalVars.currentUser.loginName,
					currentHaveReadPage, true);
		}
	}

	/**
	 * 获取已阅公文列表（构建Request）
	 * 
	 * @param request
	 * @param isReload
	 *            true是刷新 false是加载更多
	 */
	protected void buildRequestHaveRead(String aUsername, int currPage,
			boolean isReload) {
		if (isReload) {
			mHaveReadPullListView.showHeadView();
			initCenterUI(false, mHaveReadListView, mProgressHaveRead);
			isFromSearch = false;
		}
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("LogName", aUsername));
		params.add(new BasicNameValuePair("PageSize", GlobalVars.pageCount + ""));
		params.add(new BasicNameValuePair("CurrPage", currPage + ""));
		params.add(new BasicNameValuePair("DataCount", GlobalVars.DataCount
				+ ""));
		netRequestHaveRead(new OffDocHaveReadRequest(params), isReload);
	}

	/**
	 * 获取已阅公文列表
	 * 
	 * @param request
	 * @param isReload
	 *            true是刷新 false是加载更多
	 */
	private void netRequestHaveRead(AbstractRequest request,
			final boolean isReload) {
		new WcfAsyncTask(this, new OnUICallback() {

			@Override
			public void onGetResult(AbstractRequest request) {
				// dismisProgress();
				initCenterUI(true, mHaveReadListView, mProgressHaveRead);
				mHaveReadPullListView.onRefreshComplete();
				OffDocHaveReadRequest haveReadRequest = (OffDocHaveReadRequest) request;
				if (haveReadRequest.officialDocs != null) {
					if (isReload) {
						mIsLoad[1] = true;
						if (haveReadRequest.officialDocs.size() == 0) {
							mHaveReadOfficialDocs.clear();
							mHaveReadAdapter.notifyDataSetChanged();
							OfficialDocActivity.this.showToast("暂无已阅公文");
							return;
						}
						currentHaveReadPage++;
						mHaveReadOfficialDocs.clear();
					} else {
						if (haveReadRequest.officialDocs.size() == 0) {
							OfficialDocActivity.this.showToast("没有更多已阅公文");
							return;
						}
						currentHaveReadPage++;
					}
					mHaveReadOfficialDocs.addAll(haveReadRequest.officialDocs);
					mHaveReadAdapter.notifyDataSetChanged();

				}
			}

			@Override
			public void onCancel() {
				if (isReload) {
					mIsLoad[1] = false;
				}
				// dismisProgress();
				initCenterUI(true, mHaveReadListView, mProgressHaveRead);
				mHaveReadPullListView.onRefreshComplete();
			}

			@Override
			public void onProgress(int progress, String msg) {
				// dismisProgress();
				OfficialDocActivity.this.showToast(msg);
			}
		}).execute(request);
	}

	/**
	 * 获取是否是会议（构建是否是会议Request）
	 * 
	 * @param request
	 */
	public void buildRequestMeeting(String ID, String RID,
			String issuedOrIsupdateType, boolean issuedOrIsupdate,
			String readType, final int requestCode, final int position) {
		showProgress();
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("ID", ID));
		params.add(new BasicNameValuePair("RID", RID));
		netRequestMeeting(new OffDocDetailMeetingRequest(params), ID, RID,
				issuedOrIsupdateType, issuedOrIsupdate, readType, requestCode,
				position);
	}

	/**
	 * 获取是否是会议
	 * 
	 * @param request
	 */
	private void netRequestMeeting(AbstractRequest request, final String ID,
			final String RID, final String issuedOrIsupdateType,
			final boolean issuedOrIsupdate, final String readType,
			final int requestCode, final int position) {
		new WcfAsyncTask(this, new OnUICallback() {

			@Override
			public void onGetResult(AbstractRequest request) {
				isMeeting = false;
				OffDocDetailMeetingRequest meetingRequest = (OffDocDetailMeetingRequest) request;

				if (meetingRequest.success == null
						|| "".equals(meetingRequest.success)) {
					dismisProgress();
					OfficialDocActivity.this.showToast("获取会议失败，请稍后再试");
					return;
				}

				if (!meetingRequest.success.equals("0")) {
					isMeeting = true;
				}

				buildRequestApproval(ID, RID, issuedOrIsupdateType,
						issuedOrIsupdate, readType, requestCode, position);
				//
				//
				// startActivity(ID, RID, readType, issuedOrIsupdateType,
				// issuedOrIsupdate, isMeeting, requestCode,position);
			}

			@Override
			public void onCancel() {
				dismisProgress();
			}

			@Override
			public void onProgress(int progress, String msg) {
				dismisProgress();
				OfficialDocActivity.this.showToast(msg);
			}
		}).execute(request);
	}

	/**
	 * 获取是否是会议（构建是否是会议Request）
	 * 
	 * @param request
	 */
	public void buildRequestApproval(String ID, String RID,
			String issuedOrIsupdateType, boolean issuedOrIsupdate,
			String readType, final int requestCode, final int position) {
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("RID", RID));
		netRequestApproval(new OffDocApprovalRequest(params), ID, RID,
				issuedOrIsupdateType, issuedOrIsupdate, readType, requestCode,
				position);
	}

	/**
	 * 获取是否是会议
	 * 
	 * @param request
	 */
	private void netRequestApproval(AbstractRequest request, final String ID,
			final String RID, final String issuedOrIsupdateType,
			final boolean issuedOrIsupdate, final String readType,
			final int requestCode, final int position) {
		new WcfAsyncTask(this, new OnUICallback() {
			@Override
			public void onGetResult(AbstractRequest request) {
				dismisProgress();
				OffDocApprovalRequest meetingRequest = (OffDocApprovalRequest) request;
				if (meetingRequest.strBuffer != null) {
					startActivity(ID, RID, readType, issuedOrIsupdateType,
							issuedOrIsupdate, isMeeting, requestCode, position,
							meetingRequest.strBuffer.toString());
				} else {
					OfficialDocActivity.this.showToast("获取批复意见失败");
				}

			}

			@Override
			public void onCancel() {
				dismisProgress();
			}

			@Override
			public void onProgress(int progress, String msg) {
				dismisProgress();
				OfficialDocActivity.this.showToast(msg);
			}
		}).execute(request);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode,
			Intent intent) {

		if (resultCode == RESULT_OK) {
			if (requestCode == GlobalVars.TO_BE_READ) {
				mIsLoad[1] = false;
				currentToBeReadPage = 1;
				currentHaveReadPage = 1;
				buildRequestToBeRead(GlobalVars.currentUser.loginName,
						currentToBeReadPage, true);
			} else if (requestCode == GlobalVars.HAVE_READ) {
				currentHaveReadPage = 1;
				buildRequestHaveRead(GlobalVars.currentUser.loginName,
						currentHaveReadPage, true);
			}
		} else if (resultCode == 2) {
			title = intent.getStringExtra("title");
			owner = intent.getStringExtra("owner");
			from = intent.getStringExtra("from");
			beginTime = intent.getStringExtra("beginTime");
			endTime = intent.getStringExtra("endTime");

			if (requestCode == GlobalVars.TO_BE_READ) {
				currentSearchToBeReadPage = 1;
				buildSearchRequestToBeRead(GlobalVars.currentUser.loginName,
						currentSearchToBeReadPage, title, owner, from, beginTime,
						endTime, true);
			} else if (requestCode == GlobalVars.HAVE_READ) {
				currentSearchHaveReadPage = 1;
				buildSearchRequestHaveRead(GlobalVars.currentUser.loginName,
						currentSearchHaveReadPage, title, owner, from, beginTime,
						endTime, true);
			}
		}
	}

}
